package cjh;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Scanner;

import java.util.ArrayList;
import java.util.List;

import model.AdminVO;
import model.DepartVO;
import model.ProfessorVO;
import model.StudentVO;
import model.SubjectVO;
import dao.JDBC_ConnClose;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import model.AdminVO;

import dao.JDBC_SQL;
import dao.JDBC_ConnClose;
import screen.AdminMain;
import screen.LoginMain;
import screen.LoginMain;
import dao.JDBC_SQL;

public class Stu_Service {
	static 	JDBC_SQL sql = new JDBC_SQL();
	static StringBuilder sb = new StringBuilder();
	static Scanner sc = new Scanner(System.in); 
	static boolean b = true;
	static String[] smt = { "순번", "ID", "이름", "연락처", "등록일자" };
	static Connection conn = null;
	static PreparedStatement pstmt = null;
	static ResultSet rs = null;
	static String add = null;
	static String logId = LoginMain.logIdVO;
	private static String selectSQL = "select * from ADMIN_INFO order by ADMIN_TR DESC";
	private static String DepartSelectSQL = "SELECT * FROM DEPART order by DEPT_TR DESC";
	private static String StuSelectSQL = "SELECT * FROM STUDENT order by STD_TR DESC";
	private static String SubSelectSQL = "SELECT * FROM SUBJECT order by SUB_TR DESC";
	private static String profSelectSQL = "SELECT * FROM PROFESSOR order by PROF_TR DESC";
	private static String  selectSubSQL = "SELECT * FROM SUBJECT WHERE SUB_NO LIKE ? " ;
	
	
	public static List<SubjectVO> serchRegi( String val ) {
		List<SubjectVO> result = new ArrayList<>();			// 동적배열
		
	
		try {
				conn = JDBC_ConnClose.openDataBase();
				pstmt = conn.prepareStatement( selectSubSQL );
				
				pstmt.setString( 1, val+"%" );
				rs = pstmt.executeQuery();
				
				while( rs.next() ) {
					
					SubjectVO s = new SubjectVO();
					
					s.setSub_tr( rs.getString("SUB_TR") );
					s.setSub_no( rs.getString( "SUB_NO") );
					s.setSub_name( rs.getString( "SUB_NAME") );
					s.setSub_type_no( rs.getString( "SUB_TYPE_NO") );
					s.setSub_info( rs.getString("SUB_INFO") );
					s.setSub_point( rs.getString( "SUB_POINT") );
					s.setProf_no( rs.getString("PROF_NO") );
					s.setReg_date( rs.getString("REG_DATE") );
					
					result.add( s );
										
				}
				
				
		} catch ( Exception ex ) {
			ex.printStackTrace();
			
		}finally {
		
			JDBC_ConnClose.closeDataBase(conn, pstmt, rs);
		}
		
		return result;
	}
	
} //  class
	
	
